//合并请求的api回调
const apiLocks = {};
export default (options = {}) => {
  const { data = {} } = options;
  //进行加锁，防止数据多次提交
  let key = options.url + JSON.stringify(data);
  if (apiLocks[key]) {
    return Promise.reject({ msg: '请不要重复操作' });
  }
  apiLocks[key] = true;

  let optionsHeaders = options.headers || {};
  options.headers = {
    ...optionsHeaders,
    Authorization: "token"//在这个理注入token
  }

  return new Promise((resolve, reject) => {
    console.log("开始请求===", options)
    my.request({
      ...options,

      timeout: 60000,
      success: res => {
        resolve(res.data);
      },
      fail: res => {
        //请求失败
        reject(res);
      },
      complete: function (res) {
        setTimeout(() => {
          //不要立即解锁
          delete apiLocks[key];
        }, 200)
      }
    });
  });
}